/* 
 * File:   compiler.h
 * Author: fiary
 *
 * Created on May 22, 2009, 11:17 AM
 */

#ifndef _COMPILER_H
#define	_COMPILER_H
#include "stack.h"
#include <stdio.h>
#define MAX_IDEN_LEN 10
#define MAX_ARRAY_LEN 40
#define MAX_PRO_SIZE 3
typedef struct productor
{
    char left;
    int rightnum;
} productor;
productor grammar[7] =
{
    {'S',3},
    {'E',3},
    {'E',1},
    {'T',3},
    {'T',1},
    {'F',3},
    {'F',1},
};//define the grammar
int gotoState[14][4]=
{
    0,0,0,0,
    0,0,0,0,
    0,3,4,5,
    0,0,0,0,
    0,0,0,0,
    0,0,0,0,
    0,0,0,0,
    0,10,4,5,
    0,0,11,5,
    0,0,0,12,
    0,0,0,0,
    0,0,0,0,
    0,0,0,0,
    0,0,0,0
};//0->error
int action[14][7]=
{
    1,0,0,0,0,0,0,
    0,1,0,0,0,0,0,
    1,0,0,0,1,0,0,
    0,0,1,0,0,0,3,
    0,0,2,1,0,2,2,
    0,0,2,2,0,2,2,
    0,0,2,2,0,2,2,
    1,0,0,0,1,0,0,
    1,0,0,0,1,0,0,
    1,0,0,0,1,0,0,
    0,0,1,0,0,1,0,
    0,0,2,1,0,2,2,
    0,0,2,2,0,2,2,
    0,0,2,2,0,2,2
};//0->error,1->move,2->guiyue,3->acc
int actionselect[14][7]=
{
    1,0,0,0,0,0,0,
    0,2,0,0,0,0,0,
    6,0,0,0,7,0,0,
    0,0,8,0,0,0,0,
    0,0,2,9,0,2,2,
    0,0,4,4,0,4,4,
    0,0,6,6,0,6,6,
    6,0,0,0,7,0,0,
    6,0,0,0,7,0,0,
    6,0,0,0,7,0,0,
    0,0,8,0,0,13,0,
    0,0,1,9,0,1,1,
    0,0,3,3,0,3,3,
    0,0,5,5,0,5,5
};
SqStackint* stateStack ;
SqStackchar* charStack ;
FILE * fpin;
FILE * fpout;
void syntaxAnalysis();
char semantic(int,SqStackchar*);
int getSuffix(char );
#endif	/* _COMPILER_H */

